﻿package mortal.game.view.guide
{
    import Message.Public.*;
    import baseEngine.modifiers.*;
    import com.gengine.global.*;
    import com.greensock.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.utils.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.manager.*;
    import mortal.game.manager.window3d.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.scene3D.model.player.*;
    import mortal.game.scene3D.model.pools.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.fashionOnline.util.*;
    import mortal.mvc.core.*;

    public class GuideOnlineEquip extends Window
    {
        private var _timer:SecTimerView;
        private var _effectPlayer:EffectPlayer;
        private var _rect3d:Rect3DObject;
        private var _item:BaseItem;
        private var _itemData:ItemData;
        private var _tween:TweenMax;

        public function GuideOnlineEquip()
        {
            this.layer = LayerManager.uiLayer;
            this.buttonMode = true;
            this.isForbidenDrag = true;
            this.setSize(115, 100);
            return;
        }// end function

        public function showGuide() : void
        {
            this.x = Global.stage.stageWidth / 2;
            this.y = Global.stage.stageHeight / 2;
            this.hideTween();
            this._tween = TweenMax.to(this, 0.8, {x:GameController.chat.view.x + 322, y:Global.stage.stageHeight - 192});
            return;
        }// end function

        private function hideTween() : void
        {
            if (this._tween != null)
            {
                this._tween.kill();
                this.stageResize();
                this._tween = null;
            }
            return;
        }// end function

        override public function stageResize() : void
        {
            this.x = GameController.chat.view.x + 322;
            this.y = Global.stage.stageHeight - 156 + 20 - 56;
            return;
        }// end function

        public function updateLeftTime(param1:int = 0) : void
        {
            var _loc_2:int = 0;
            var _loc_3:int = 0;
            if (param1 == 0)
            {
                _loc_2 = OnlineRewardConfig.instance.getInfoById(1).onlineTime;
                _loc_3 = _loc_2 * 3600 - Cache.instance.role.playerInfo.onlineTime - getTimer() / 1000 + 8 + 70;
                this._timer.setLeftTime(_loc_3);
            }
            else
            {
                this._timer.setLeftTime(param1);
            }
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            _isAddClolseButton = false;
            super.createDisposedChildrenImpl();
            var _loc_1:* = Language.getString(35319);
            var _loc_2:* = GlobalStyle.textFormatFenHong;
            _loc_2.size = 15;
            _loc_2.bold = true;
            this._timer = UIFactory.secTimeView(_loc_1, -22, 4, 110, 24, this, _loc_2);
            this._timer.mouseEnabled = true;
            this._timer.timeOutHandler = this.timeOutHandler;
            this._timer.configEventListener(MouseEvent.MOUSE_OVER, this.onOverHandler);
            this._timer.configEventListener(MouseEvent.MOUSE_OUT, this.onOutHandler);
            this._timer.configEventListener(MouseEvent.CLICK, this.clickMeHandler);
            this._item = UICompomentPool.getUICompoment(BaseItem);
            this._item.setSize(96, 96);
            this._item.bgName = "";
            this._item.x = -17;
            this._item.y = -96;
            this.addChild(this._item);
            this._item.mouseEnabled = true;
            this._item.configEventListener(MouseEvent.CLICK, this.clickItemHandler);
            this.initRect3d();
            this.updateInfo();
            this.addListeners();
            return;
        }// end function

        private function addListeners() : void
        {
            NetDispatcher.addCmdListener(ServerCommand.FashionOnlineFashionUpdate, this.onFashionUpdate);
            return;
        }// end function

        private function removeListeners() : void
        {
            NetDispatcher.removeCmdListener(ServerCommand.FashionOnlineFashionUpdate, this.onFashionUpdate);
            return;
        }// end function

        private function initRect3d() : void
        {
            this._rect3d = Rect3DManager.instance.registerWindow(false, new Rectangle(30, 30, 10, 10), this);
            Rect3DManager.instance.windowShowHander(null, this);
            return;
        }// end function

        private function onFashionUpdate(param1:Object) : void
        {
            this.updateInfo();
            return;
        }// end function

        private function updateInfo() : void
        {
            var _loc_1:* = FashionOnlineUtil.getRewardItemCodeById(1);
            this._itemData = new ItemData(_loc_1);
            this.updateEffectPlayer();
            this.updateTips();
            return;
        }// end function

        private function updateEffectPlayer() : void
        {
            var _loc_1:int = 0;
            var _loc_2:String = null;
            if (this._rect3d)
            {
                this.removeEffect();
                _loc_1 = Cache.instance.role.entityInfo.career;
                switch(_loc_1)
                {
                    case ECareer._ECareerWarrior:
                    {
                        _loc_2 = "wuqizhanshi-zs";
                        break;
                    }
                    case ECareer._ECareerArcher:
                    {
                        _loc_2 = "wuqizhanshi-gs";
                        break;
                    }
                    case ECareer._ECareerMage:
                    {
                        _loc_2 = "wuqizhanshi-fs";
                        break;
                    }
                    case ECareer._ECareerPriest:
                    {
                        _loc_2 = "wuqizhanshi-zs";
                        break;
                    }
                    default:
                    {
                        break;
                    }
                }
                this._effectPlayer = EffectPlayerPool.instance.getEffectPlayer(_loc_2, null, this._rect3d.renderList, false);
                this._effectPlayer.play(PlayMode.ANIMATION_LOOP_MODE);
                this._rect3d.addObject3d(this._effectPlayer, 0, 0);
                this._effectPlayer.setScale(0.8, 0.8, 0.8);
            }
            return;
        }// end function

        private function updateTips() : void
        {
            this._item.toolTipData = this._itemData;
            return;
        }// end function

        private function timeOutHandler() : void
        {
            this._timer.text = Language.getString(35320);
            this._timer.x = -15;
            EffectManager.glowFilterReg(this._timer, [FilterConst.fashionOnlineFilter]);
            return;
        }// end function

        private function clickMeHandler(event:MouseEvent) : void
        {
            if (this._timer.running)
            {
                MsgManager.showRollTipsMsg(this._timer.text);
                return;
            }
            GameController.fashionOnline.view.show();
            return;
        }// end function

        private function clickItemHandler(event:MouseEvent) : void
        {
            GameController.fashionOnline.view.show();
            return;
        }// end function

        private function onOverHandler(event:MouseEvent) : void
        {
            CursorManager.showCursor(CursorManager.BUTTON);
            return;
        }// end function

        private function onOutHandler(event:MouseEvent) : void
        {
            CursorManager.hideFromButton();
            return;
        }// end function

        private function removeEffect() : void
        {
            if (this._effectPlayer)
            {
                this._rect3d.disposeObj3d(this._effectPlayer);
                this._effectPlayer = null;
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this.hideTween();
            if (this._timer != null)
            {
                this._timer.stop();
                this._timer.dispose(param1);
                this._timer = null;
            }
            EffectManager.glowFilterUnReg(this._timer);
            this._itemData = null;
            this.removeEffect();
            Rect3DManager.instance.disposeRect3d(this._rect3d);
            this._rect3d = null;
            this.removeListeners();
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            super.show(param1, param2);
            this.stageResize();
            return;
        }// end function

    }
}
